﻿#include "appupdatereq.h"

AppUpdateReq::AppUpdateReq() : BaseMsg(MSG_TYPE_APP_UPDATE_REQ)
{
    fileData = NULL;
    fileLen = 0;
}

AppUpdateReq::~AppUpdateReq()
{
    SafeDeleteArray(fileData);
    fileLen = 0;
}

int AppUpdateReq::decodeParametersFromTlv(TLV *tlv)
{
    if(tlv->tag == AppUpdateReqTag_app)
    {
        app = tlv->buffer;
    }
    else if(tlv->tag == AppUpdateReqTag_fileName)
    {
        fileName = tlv->buffer;
    }
    else if (tlv->tag == AppUpdateReqTag_fileData)
    {
        tlv->needReleaseBuffer = false;
        fileData = (byte *)tlv->buffer;
        fileLen = tlv->length;
    }
    return f_success;
}

int AppUpdateReq::encodeParametersIntoTlvs(list<TLV *> &tlvs)
{

    tlvs.push_back(createTlvByStringValue(AppUpdateReqTag_app, app));
    tlvs.push_back(createTlvByStringValue(AppUpdateReqTag_fileName, fileName));
    tlvs.push_back(createTlvByBufferValue(AppUpdateReqTag_fileData, fileLen, fileData));
    return f_success;
}
